package com.pianzhu.blockchainemr.controller;

import com.pianzhu.blockchainemr.pojo.*;
import com.pianzhu.blockchainemr.pojo.Param.OperationLogQuery;
import com.pianzhu.blockchainemr.pojo.result.PageResult;
import com.pianzhu.blockchainemr.pojo.result.RecentActivitiesResult;
import com.pianzhu.blockchainemr.pojo.result.Result;
import com.pianzhu.blockchainemr.pojo.result.StatisticsResult;
import com.pianzhu.blockchainemr.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;

    @GetMapping("/getDeptList")
    public Result getDeptList() {
        List<EmrDeptDict> deptList = adminService.getDeptList();
        return Result.success(deptList);
    }

    @PostMapping("/addDept")
    public Result addDept(@RequestBody EmrDeptDict dept) {
        adminService.addDept(dept);
        return Result.success();
    }

    @PostMapping("/updateDept")
    public Result updateDept(@RequestBody EmrDeptDict dept) {
        adminService.updateDept(dept);
        return Result.success();
    }

    @PostMapping("/deleteDept")
    public Result deleteDept(@RequestBody EmrDeptDict dept) {
        adminService.deleteDept(dept);
        return Result.success();
    }

    @GetMapping("/getDiseaseList")
    public Result getDiseaseList() {
        List<EmrDiseaseDict> diseaseList = adminService.getDiseaseList();
        return Result.success(diseaseList);
    }

    @PostMapping("/addDisease")
    public Result addDisease(@RequestBody EmrDiseaseDict disease) {
        adminService.addDisease(disease);
        return Result.success();
    }

    @PostMapping("/updateDisease")
    public Result updateDisease(@RequestBody EmrDiseaseDict disease) {
        adminService.updateDisease(disease);
        return Result.success();
    }

    @PostMapping("/deleteDisease")
    public Result deletDisease(@RequestBody EmrDiseaseDict disease) {
        adminService.deleteDisease(disease);
        return Result.success();
    }

    @GetMapping("/getExamItemList")
    public Result getExamItemList() {
        List<EmrExamItemDict> examItemList = adminService.getExamItemList();
        return Result.success(examItemList);
    }

    @PostMapping("/addExamItem")
    public Result addExamItem(@RequestBody EmrExamItemDict examItem) {
        adminService.addExamItem(examItem);
        return Result.success();
    }
    @PostMapping("/updateExamItem")
    public Result updateExamItem(@RequestBody EmrExamItemDict examItem) {
        adminService.updateExamItem(examItem);
        return Result.success();
    }
    @PostMapping("/deleteExamItem")
    public Result deleteExamItem(@RequestBody EmrExamItemDict examItem) {
        adminService.deleteExamItem(examItem);
        return Result.success();
    }

    @GetMapping("/getDrugList")
    public Result getDrugList() {
        List<EmrDrugDict> drugList = adminService.getDrugList();
        return Result.success(drugList);
    }

    @PostMapping("/addDrug")
    public Result addDrug(@RequestBody EmrDrugDict drug) {
        adminService.addDrug(drug);
        return Result.success();
    }

    @PostMapping("/updateDrug")
    public Result updateDrug(@RequestBody EmrDrugDict drug) {
        adminService.updateDrug(drug);
        return Result.success();
    }

    @PostMapping("/deleteDrug")
    public Result deleteDrug(@RequestBody EmrDrugDict drug) {
        adminService.deleteDrug(drug);
        return Result.success();
    }

    @GetMapping("/getStatistics")
    public Result getStatistics() {
        StatisticsResult statisticsResult = adminService.getStatistics();
        return Result.success(statisticsResult);
    }

    @GetMapping("/getRecentActivitiesResult")
    public Result getRecentActivitiesResult() {
        List<RecentActivitiesResult> recentActivitiesResultList = adminService.getRecentActivitiesResult();
        return Result.success(recentActivitiesResultList);
    }

    @GetMapping("/getOperationList")
    public Result getOperationList(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer size,
                                   @RequestParam(required = false) String module,
                                   @RequestParam(required = false) String operation,
                                   @RequestParam(required = false) String operatorName,
                                   @RequestParam(required = false) String status) {
        OperationLogQuery query = new OperationLogQuery();
        query.setPage(page);
        query.setSize(size);
        query.setModule(module);
        query.setOperation(operation);
        query.setOperatorName(operatorName);
        query.setStatus(status);

        PageResult<OperationLog> result = adminService.getOperationList(query);
        return Result.success(result);
    }

}
